package com.weaver.qfengx.api.qihoo;

import com.weaver.qfengx.LogUtils;
import com.weaver.qfengx.NumberUtils;
import com.weaver.qfengx.PropUtils;
import okhttp3.OkHttpClient;

/**
 * 奇虎360 查杀云API配置类
 */
public class FileScannerConfig {

    private static final LogUtils log = new LogUtils(FileScannerConfig.class);

    private String host = "http://127.0.0.1";
    private String port = "8080";
    private String verison = "v1";
    private String appid = "";
    private String secret = "";
    private OkHttpClient okHttpClient;
    private int virusLevel = 50;
    private String logTable;

    public static FileScannerConfig build(String host, String port, String version, String appid, String secret, int virusLevel, String logTable) {
        return new FileScannerConfig()
                .setHost(host)
                .setPort(port)
                .setVerison(version)
                .setAppid(appid)
                .setSecret(secret)
                .setVirusLevel(virusLevel)
                .setLogTable(logTable)
                .setOkHttpClient(new OkHttpClient());
    }

    public static FileScannerConfig build(String host, String port, String appid, String secret) {
        return build(host, port, "v1", appid, secret, 50, "");
    }

    public static FileScannerConfig build(String host, String appid, String secret) {
        return build(host, "8080", appid, secret);
    }

    public static FileScannerConfig build(String appid, String secret) {
        return build("http://127.0.0.1", appid, secret);
    }

    /**
     * 读取prop配置文件属性
     * host;port;version;appid;secret
     * @param filename
     * @return
     */
    public static FileScannerConfig buildForPropFile(String filename) {
        log.writeLog("奇虎360云查杀 读取加载配置文件 => " + filename);
        FileScannerConfig config = build(PropUtils.get(filename, "host", "127.0.0.1"),
                PropUtils.get(filename, "port", "8080"),
                PropUtils.get(filename, "version", "v1"),
                PropUtils.get(filename, "appid"), PropUtils.get(filename, "secret"),
                NumberUtils.parseInt(PropUtils.get(filename, "virus.level", "50"), 50),
                PropUtils.get(filename, "log.table"));
        log.writeLog("奇虎360云查杀 完成加载配置文件 config => " + config);
        return config;
    }

    public String getHost() {
        return host;
    }

    public FileScannerConfig setHost(String host) {
        this.host = host;
        return this;
    }

    public String getPort() {
        return port;
    }

    public FileScannerConfig setPort(String port) {
        this.port = port;
        return this;
    }

    public String getVerison() {
        return verison;
    }

    public FileScannerConfig setVerison(String verison) {
        this.verison = verison;
        return this;
    }

    public String getAppid() {
        return appid;
    }

    public FileScannerConfig setAppid(String appid) {
        this.appid = appid;
        return this;
    }

    public String getSecret() {
        return secret;
    }

    public FileScannerConfig setSecret(String secret) {
        this.secret = secret;
        return this;
    }

    public OkHttpClient getOkHttpClient() {
        return okHttpClient;
    }

    public FileScannerConfig setOkHttpClient(OkHttpClient okHttpClient) {
        this.okHttpClient = okHttpClient;
        return this;
    }

    public int getVirusLevel() {
        return virusLevel;
    }

    public FileScannerConfig setVirusLevel(int virusLevel) {
        this.virusLevel = virusLevel;
        return this;
    }

    public String getLogTable() {
        return logTable;
    }

    public FileScannerConfig setLogTable(String logTable) {
        this.logTable = logTable;
        return this;
    }

    @Override
    public String toString() {
        return "FileScannerConfig{" +
                "host='" + host + '\'' +
                ", port='" + port + '\'' +
                ", verison='" + verison + '\'' +
                ", appid='" + appid + '\'' +
                ", secret='" + secret + '\'' +
                ", okHttpClient=" + okHttpClient +
                ", virusLevel=" + virusLevel +
                ", logTable='" + logTable + '\'' +
                '}';
    }
}
